using Render;

namespace Noise
{
    public static class PermutationArray
    {
        public static uint[] Perm2(int width, int height)
        {
            int i0, j0, i1, j1;
            byte p00, p10, p01, p11;

            uint[] permutations = new uint[width*height];

            // For each i,j lattice point, store the surrounding perm values at i,j,i+1,j+1
            for (int j=0; j<height; j++)
            {
                for (int i=0; i<width; i++)
                {
                    // Wrap integer coords at 255
                    i0 = i&255;
                    j0 = j&255;
                    i1 = (i+1)&255;
                    j1 = (j+1)&255;

                    // Hash coordinates at the 4 square corners
                    p00 = Permutation.Perm2(i0, j0);
                    p10 = Permutation.Perm2(i1, j0);
                    p01 = Permutation.Perm2(i0, j1);
                    p11 = Permutation.Perm2(i1, j1);

                    permutations[(j*width)+i] = Colors.UInt32FromRGBA(p00, p10, p01, p11);
                }
            }

            return permutations;
        }
    }
}